extends IEventBehavior


class_name HitRange
"""
击中时受到伤害
"""


## 需要操作的RangeComponent组件名称
@export var range_name: String = ""
## 需要执行的操作
@export var method: RangeComponent.RangeMethod = RangeComponent.RangeMethod.None

## 需要检测的碰撞层
@export_flags_2d_physics  var hit_layer: int  = 0


func support() -> Array:
    return [0, CharacterUnit.Event.ON_HIT_SOMETHING]

## 处理武器命中事件,返回是否取消销毁子弹
func do_event(character: CharacterComponent, v: EffectValue, e: CharacterEvent) -> void:
    if e.meta.body is HurtBoxComponent and BehaviorHelper.is_layer(hit_layer, e):
        var range: RangeComponent = character.subassembly(range_name)
        if range:
            range.execute(method, v.value)
